package com.ophiux.cs.domain.sign.domainservice;

import java.util.Date;

import org.springframework.stereotype.Service;

import com.ophiux.utils.common.DateUtil;
import com.ophiux.utils.common.StringUtil;
import com.ophiux.utils.sign.OphiuxSignUtil;

/**
 * 签名相关核心验证服务
 * @author ADMIN
 *
 */
@Service
public class SignDomainService {
	
	public static final String SignKey = "ophiux_cszxwz@2018";
	
	/**
	 * 验证sign值
	 * @param signStr 加密字符串
	 * @return true 验证成功 false 验证失败
	 */
	public boolean verSign(String signStr) {
		try {
			//解密  加密字段
			String sign = OphiuxSignUtil.decrypt(signStr);
			if(sign.trim().contains(OphiuxSignUtil.sign_key)) {
				return true;
			}else {
				return false;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		
	}
	
	/**
	 * 获取sign值
	 * @param _key 密钥 可外部传入  默认SignKey
	 * @return 加密字符串
	 */
	public String getSign(String _key) {
		String key = StringUtil.isEmpty(_key)?SignKey:_key;
		String nowdate = DateUtil.getStrDate(new Date(), DateUtil.DateFormat.YYYYMMDDHHMMSS);
		String sign = OphiuxSignUtil.encrypt(nowdate, key);
		return sign;
	}
	public static void main(String[] args) {
		String nowdate = DateUtil.getStrDate(new Date(), DateUtil.DateFormat.YYYYMMDDHHMMSS);
		String sign = OphiuxSignUtil.encrypt(nowdate, SignKey);
		System.out.println(sign);
	}
}
